import RPi.GPIO as GPIO
import time

# 设置GPIO模式
GPIO.setmode(GPIO.BCM)

# 设置GPIO18为输出模式
GPIO.setup(2, GPIO.OUT)

try:
    while True:
        # 点亮LED
        GPIO.output(2, GPIO.HIGH)
        time.sleep(1)  # 等待1秒

        # 熄灭LED
        GPIO.output(2, GPIO.LOW)
        time.sleep(1)  # 等待1秒
except KeyboardInterrupt:
    # 捕获Ctrl+C，清理GPIO
    GPIO.cleanup()